﻿#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Storage;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
#endregion

namespace TheSpirit
{
    class ShortCutWindow
    {
        #region Declaration

        Texture2D fireTexture;
        Texture2D waterTexture;
        Texture2D forestTexture;
        Texture2D upgradeTexture;
        
        bool isSelectFire;
        bool isSelectWater;
        bool isSelectForest;
        bool isSelectUpgrade;

        Rectangle firePosition;
        Rectangle waterPosition;
        Rectangle forestPosition;
        Rectangle upgradePosition;

        const int CARDNUM = 3;

        #endregion


        #region Properties

        public bool IsSelectFire
        {
            set { isSelectFire = value; }
            get { return isSelectFire; }
        }
        public bool IsSelectWater
        {
            set { isSelectWater = value; }
            get { return isSelectWater; }
        }
        public bool IsSelectForest
        {
            set { isSelectForest = value; }
            get { return isSelectForest; }
        }
        public bool IsSelectUpgrade
        {
            set { isSelectUpgrade = value; }
            get { return isSelectUpgrade; }
        }
        public Rectangle FirePosition
        {
            get { return firePosition; }
        }

        #endregion


        #region Initialize

        public ShortCutWindow()
        {
            firePosition = new Rectangle(0, 0, 0, 0);
            waterPosition = new Rectangle(0, 0, 0, 0);
            forestPosition = new Rectangle(0, 0, 0, 0);
        }

        public void LoadContent(ContentManager content)
        {
            fireTexture = content.Load<Texture2D>("Strategy/FireButton");
            waterTexture = content.Load<Texture2D>("Strategy/WaterButton");
            forestTexture = content.Load<Texture2D>("Strategy/ForestButton");
            upgradeTexture = content.Load<Texture2D>("Strategy/UpButton");

            //위치 수정 필요
            int w = fireTexture.Width;
            int h = fireTexture.Height;
            int x = Constants.WIDTH * 60 / 1280;
            int y = Constants.HEIGHT * 20 / 720;

            firePosition = new Rectangle(x, y, fireTexture.Width, fireTexture.Height);
            x += Constants.WIDTH * 210 / 1280;
            waterPosition = new Rectangle(x, y, waterTexture.Width, waterTexture.Height);
            x += Constants.WIDTH * 210 / 1280;
            forestPosition = new Rectangle(x, y, forestTexture.Width, forestTexture.Height);
            x += Constants.WIDTH * 210 / 1280;
            upgradePosition = new Rectangle(x, y, upgradeTexture.Width, upgradeTexture.Height);
        }

        #endregion


        #region Update & Draw

        public void Update(int fire, int water, int forest, int upgrade)
        {
            UpdateCursor();

            if (InputManager.IsLeftClicked())
            {
                if (InputManager.MousePosition.Intersects(firePosition))
                {
                    if(fire > 0)
                        isSelectFire = true;
                }
                if (InputManager.MousePosition.Intersects(waterPosition))
                {
                    if(water > 0)
                        isSelectWater = true;
                }
                if (InputManager.MousePosition.Intersects(forestPosition))
                {
                    if(forest > 0)
                        isSelectForest = true;
                }
                if (InputManager.MousePosition.Intersects(upgradePosition))
                {
                    if (upgrade > 0)
                        isSelectUpgrade = true;
                }
            }
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            //각 속성 아이콘 출력
            spriteBatch.Draw(fireTexture, firePosition, Color.White);
            spriteBatch.Draw(waterTexture, waterPosition, Color.White);
            spriteBatch.Draw(forestTexture, forestPosition, Color.White);
            spriteBatch.Draw(upgradeTexture, upgradePosition, Color.White);
        }

        #endregion


        #region Helper

        public void UpdateCursor()
        {
            if (InputManager.MousePosition.Intersects(firePosition) ||
                InputManager.MousePosition.Intersects(waterPosition) ||
                InputManager.MousePosition.Intersects(forestPosition) ||
                InputManager.MousePosition.Intersects(upgradePosition))
            {
                InputManager.ChangeMouseCursor("Select");
            }
        }

        #endregion
    }
}
